package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * JDBC java database connectivity    java 数据库连接
 *
 * */
public class JDBCDemo1 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        /**
         * jdbc 连接数据库大致步骤
         * */

        Class.forName("com.mysql.cj.jdbc.Driver");//mysql 的驱动类写法是固定的
        Connection connection=DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/bird?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root","root");
        System.out.println("与数据库连接成功");
        //3.通过链接
        Statement statement = connection.createStatement();
        String sql = "CREATE TABLE userinfo( " +
                "    id INT PRIMARY KEY  AUTO_INCREMENT, " +
                "    username VARCHAR(30), " +
                "    password VARCHAR(30), " +
                "    nickname VARCHAR(30), " +
                "    age INT(3) " +
                ")";
        statement.execute(sql);
        System.out.println("表创建成功");
        connection.close();//当不再操作数据库时，关闭链接，释放资源
    }
}
